const fetch = require("node-fetch");
exports.handler = (req, resp, context) => {
  // console.log('req',req)
  console.log('req.queries', req.queries)
  console.log('req.body', req.body)
  console.log('req.query', req.query)
  var code = req.queries.code || '400030';

  var pagesize = req.queries.pagesize || 780;
  console.log('req.code=>', code, pagesize)
  let u = `https://ms.jr.jd.com/gw/generic/jj/h5/m/getFundHistoryNetValuePageInfo`;
  fetch(u, {
    "headers": {
      "accept": "application/json, text/plain, */*",
      "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
      "content-type": "application/x-www-form-urlencoded",
    },
    "body": `reqData={"fundCode":"${code}","pageNum":1,"pageSize":${pagesize},"channel":"9"}`,
    "method": "POST",
  })
    .then(res => res.json())
    .then(res => {
      // console.log('res',res);
      var resultData = res.resultData || {};
      var datas = resultData.datas || {};
      var netValueList = datas.netValueList || [];
      console.log('netValueList', netValueList[0] || '没有获取到值');
      resp.send(JSON.stringify(netValueList));
    }).catch(err => {
      resp.send(JSON.stringify('error'));
    })
}

